package edison.persistence;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.jcr.RepositoryException;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Id;
import javax.persistence.Persistence;
import javax.persistence.Query;

import edison.jcr.SessionContext;
import edison.utils.Configuration;

public class Program {

	public static void main(String[] args) throws RepositoryException {

		EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("open.jcr");
		EntityManager entityManager = entityManagerFactory.createEntityManager();

		entityManager.getTransaction().begin();
		
		
		List<ColumnValue> cs=new ArrayList<ColumnValue>();
		cs.add(new ColumnValue("IDENTIFIER","1234567"));
		cs.add(new ColumnValue("PATH","a/b/c"));
		Dialect dialect = Configuration.getDialect();
		dialect.insertNode(new SessionContext(null, entityManager), "nt:test", cs);
		Query q = entityManager.createNativeQuery("SELECT * FROM nt_test");
		Object c = q.getSingleResult();
		System.out.println(c.getClass().getName());
		entityManager.getTransaction().commit();
		entityManager.close();
		System.out.println("OK");
	}

	private static NodeTypeBean createNT() {
		NodeTypeBean ntb = new NodeTypeBean();
		ntb.setName("nt:nb");

		NodeDefinitionBean ndb = new NodeDefinitionBean();
		ndb.setName("nd:node_def");
		ntb.getDeclaredChildNodeDefinitions().add(ndb);

		return ntb;
	}

}